package com.group4.xiao_ge_lai_yi_zhu.controller.login_controller;


import com.group4.xiao_ge_lai_yi_zhu.controller.change_prize_controller.TalkAboutIt;
import com.group4.xiao_ge_lai_yi_zhu.entry.Entry;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

/**
 * 主页面
 * 用户登录之后可以看到的页面
 * 对接用户操作
 */
public class HomePage {

    Scanner sc = new Scanner(System.in);
    private BuyPage buyPage = new BuyPage();

    public void page() {
        Entry entry = new Entry();
        //用户登录之后可以看到的页面
        while (true) {
            System.out.println("请输入您的选择: 1.购买彩票  2.查看往期中奖号码 3.查看中奖级别 4.注销");
            String next = sc.next();
            switch (next) {
                case "1":
                    buyPage.buyLottery();
                    //System.out.println("购买彩票");
                    break;
                case "2":
                    PreviousNumber();
                    //System.out.println("往期中奖号码");
                    break;
                case "3":
//                    System.out.println("查看中奖级别");
                    TalkAboutIt talkAboutIt = new TalkAboutIt();
                    talkAboutIt.talkAbout();
                    break;
                case "4":
                    entry.entry();
                    break;
                default:
                    System.out.println("您的输入有误, 请重新输入");
                    break;
            }
        }
    }

    public void PreviousNumber() {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader("main_interface\\用户购买信息\\PreviousNumber.txt"));
            String a;
            while ((a = br.readLine()) != null) {
                System.out.println("开奖时间:    " + a.substring(0, 10) +
                        "    期数:    " + a.substring(11, 18) +
                        "    红球号码:    " + a.substring(19, 31) +
                        "    蓝球号码:    " + a.substring(31, 33) +
                        "    一等奖人数:    " + a.substring(33, 35) +
                        "    二等奖人数:    " + a.substring(36, a.length()));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}